<template>
    <view class="content">
        <view class="u-p-b-20">
            <u-search bg-color="#fff" :show-action="false" v-model="keyword" shape="round" placeholder="请输入内容" @search="doSearch"></u-search>
        </view>
        
        <view class="item" v-for="(item, index) in list" :key="index">
            <view class="item-top">
                <image :src="item.image || '/static/icon/avatar.png'" class="avatar"></image>
                <view class="item-top-r">
                    <view class="item-top-r-t">
                        <view class="u-flex">
                            <view class="name">{{item.user_name}}</view>
                            <view class="u-flex">
                                <image src="../../static/icons/tel_03.png" class="tel-03"></image>
                                <view>{{item.phone}}</view>
                            </view>
                        </view>
                        <!-- user_status 1启用 2禁用。 work_status 1在职 2离职 3申请离职 -->
                        <view class="ban" v-if="item.user_status == 2">禁用</view>
                    </view>
                    <view>门店名称：{{item.stores_name}}</view>
                    <view>待结佣金：{{item.pending_money}}元</view>
                </view>
            </view>
            <view class="btns">
                <view @click="$gTo('../person/person-details?id=' + item.id)">编辑</view>
                <view @click="del(item)">删除</view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
        
        <view class="btn" @click="$gTo('../person/person-details')">添加经纪人</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [], 
                keyword: '',
            }
        },
        onShow() {
            this.page = 1
            this.list = []
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            del(item) {
                uni.showModal({
                	title: '提示',
                	content: '确定删除吗？',
                	confirmColor:'#033685',
                	success: (res) => {
                        if (res.confirm) {
                            this.$ajax('user_delete', {
                            	user_token: this.$getSync('userToken'),
                            	id: item.id,
                            }).then(ret => {
                            	if (ret.success == 1000) {
                            		this.$toast('删除成功');
                                    setTimeout(() => {
                                        this.doSearch()
                                    }, 500)
                            	} else {
                            		this.$toast(ret.msg);
                            	}
                            });
                        } else if (res.cancel) {
                            
                        }
                	}
                });
            },
            
            doSearch() {
                this.page = 1
                this.list = []
                this.status = 'loadmore'
                this.getList()
            },
            
            // 获取列表
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('users_manage', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    type: 1,//1人员管理 2工资管理 3考勤打卡
                    name: this.keyword,//搜索
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail.data.length > 0) {
            				this.list = this.list.concat(ret.detail.data);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        },
    }
</script>

<style lang="scss">
    page{
        background-color: #f5f5f5;
    }
    .content{
        padding: 20rpx 20rpx 150rpx;
    }
    .item{
        background-color: #fff;
        padding: 25rpx;
        border-radius: 20rpx;
        margin-bottom: 20rpx;
    }
    .item-top{
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
    }
    .avatar{
        width: 75rpx;
        height: 75rpx;
        border-radius: 50%;
        margin-right: 15rpx;
    }
    .item-top-r{
        flex: 1;
    }
    .item-top-r-t{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 10rpx;
        font-size: 26rpx;
    }
    .name{
        font-size: 32rpx;
        font-weight: bold;
        max-width: 275rpx;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .tel-03{
        width: 18rpx;
        height: 26rpx;
        margin-left: 15rpx;
        margin-right: 10rpx;
    }
    .ban{
        font-size: 23rpx;
        color: #ff5757;
        padding: 6rpx 14rpx;
        background-color: #ffeaea;
        border-radius: 5rpx;
    }
    .btns{
        display: flex;
        justify-content: flex-end;
        align-items: center;
        padding-top: 5rpx;
    }
    .btns>view{
        font-size: 24rpx;
        color: #5f8fbe;
        padding: 10rpx 30rpx;
        border-radius: 50rpx;
        border: 2rpx solid #5f8fbe;
        margin-left: 15rpx;
    }
    
    
    .btn{
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 9;
        width: 100vw;
        font-size: 34rpx;
        color: #fff;
        text-align: center;
        padding: 25rpx;
        background-color: #00a1e9;
    }
</style>
